/** 
* @file ordered_array.h
* Interface for ordered array operations (inserting, creating, deleting)
* Inspired (alomost copied) by JamesM's kernel development tutotrials.
*
* Copyrights 2010 Michal Saman, m.saman@designplus.cz.
* This source code is release under the Apache License 2.0.
* http://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef _ORDERED_ARRAY_H
#define _ORDERED_ARRAY_H

#include <env.h>
#include <stdint.h>

/**
* Our ordered array can stored pointer to any data.
*/


/** 
* Prototype for functiong which should return NONzero if the first argument is less then second (A1 < A2).
*/
typedef int8_t (*lessthan_t)(type_t,type_t);

/**
* Structure for descriptiong ordered array.
*/
typedef struct {
	type_t *entries;		/*<< Pointer to start of array entries data. */
	uint32_t size;			/*<< Count of entries. */
	uint32_t max_size;		/*<< Maximum count of entries that can array store. */
	lessthan_t less_than;	/*<< Pointer to less_than routine. */
} ord_array_t;

int8_t std_lessthan(type_t a, type_t b);

ord_array_t ord_array_create(void* addr, uint32_t max_size, lessthan_t less_than);

extern void ord_array_destroy(ord_array_t *ord_array);
extern bool ord_array_insert(type_t item, ord_array_t *ord_array);
extern bool ord_array_delete(uint32_t i, ord_array_t *ord_array);
extern type_t ord_array_lookup(uint32_t i, ord_array_t *ord_array);

#endif
